package 分治回溯.数独;


import java.util.Scanner;

/*
005300000
800000020
070010500
400005300
010070006
003200080
060500009
004000030
000009700
*/
public class ShuDu {
    public static void main(String[] args) {
        int[][] board = new int[9][9];
        Scanner input = new Scanner(System.in);
        for (int i = 0; i < 9; i++) {
            String line = input.nextLine();
            for (int j = 0; j < line.length(); j++) {
                board[i][j] = line.charAt(j) - '0';
            }
        }
        solve(0,0,board);
    }

    private static void solve(int row, int col, int[][] board) {
        if (row == board.length){
            printBoard(board);
        }else {
            if (board[row][col] == 0){
                for (int num = 1; num <= 9 ; num++) {
                    if (!isExist(row,col,num,board)){
                        board[row][col] = num;
                        solve(row + (col + 1) / board.length,(col + 1) % board.length,board);
                    }
                    board[row][col] = 0;
                }
            }else {
                solve(row + (col + 1) / board.length,(col + 1) % board.length,board);

            }
        }

    }

    private static boolean isExist(int row, int col, int num, int[][] board) {
        for (int c = 0; c < board.length; c++) {
            if (board[row][c] == num){
                return true;
            }
        }

        for (int r = 0; r < board.length; r++) {
            if (board[r][col] == num){
                return true;
            }
        }

        int rowMin = 0;
        int rowMax = 0;
        int colMin = 0;
        int colMax = 0;

        if (row >=0 && row <= 2){
            rowMin = 0;
            rowMax = 2;
        }

        if (row >= 3 && row <= 5){
            rowMin = 3;
            rowMax = 5;
        }

        if (row >= 6 && row <= 8){
            rowMin = 6;
            rowMax = 8;
        }

        if (col >= 0 && col <= 2){
            colMin = 0;
            colMax = 2;
        }

        if (col >= 3 && col <= 5){
            colMin = 3;
            colMax = 5;
        }

        if (col >= 6 && col <= 8){
            colMin = 6;
            colMax = 8;
        }

        for (int r = rowMin; r <= rowMax ; r++) {
            for (int c = colMin; c <= colMax; c++) {
                if (board[r][c] == num){
                    return true;
                }
            }

        }

        return false;
    }

    private static void printBoard(int[][] board) {
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < board[i].length; j++) {
                System.out.print(board[i][j] + " ");
            }
            System.out.println();
        }
    }

}
